package previous.Test_0306;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Solution {
    //等差数列划分
    //状态表示：
    //dp[i]:以i结尾有多少个等差数列个数
    //转移状态方程：
    public int numberOfArithmeticSlices(int[] nums) {
        int n=nums.length;
        int[] dp=new int[n];
        if(n==1 || n==2) return 0;
        int sum=0;
        for (int i = 2; i < n; i++) {
            dp[i]=nums[i-1]-nums[i-2]==nums[i]-nums[i-1]? dp[i]+1:0;
            sum+=dp[i];
        }
        return sum;
    }
}
